var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.UIViewShowType = undefined;
var c;
var EventManager = require("AA_EventManager");
var LogManager = require("AA_LogManager");
var ResKeeper = require("AA_ResKeeper");
var UIManager = require("AA_UIManager");
var UITools = require("AA_UITools");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;
var _menu = _decorator.menu;
!function (e) {
  e[e.Normal = 0] = "Normal";
  e[e.Sclae = 1] = "Sclae";
  e[e.Opacity = 2] = "Opacity";
}(c = exports.UIViewShowType || (exports.UIViewShowType = {}));
var _def_UIView = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t._scene = false;
    t.isCache = false;
    t.isFull = false;
    t.showType = c.Normal;
    t.auto_ui = null;
    t._params = null;
    t._eventMap = new Map();
    t._hideViews = [];
    t._actTime = .2;
    return t;
  }
  __extends(_creator, e);
  Object.defineProperty(_creator.prototype, "params", {
    get: function () {
      return this._params;
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(_creator.prototype, "bundleName", {
    get: function () {
      return this._bundleName;
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(_creator.prototype, "uiName", {
    get: function () {
      return this._uiName;
    },
    enumerable: false,
    configurable: true
  });
  _creator.prototype.init = function (e, t, o) {
    this._bundleName = e;
    this._uiName = t;
    this._params = o;
    this._addClickListener();
    this._addEventListener();
    this._show.apply(this, o);
    this._showOpenAnim();
  };
  _creator.prototype._close = function () {
    UIManager.default.close(this);
  };
  _creator.prototype.onResume = function (e) {
    var t = [];
    for (var o = 1; o < arguments.length; o++) {
      t[o - 1] = arguments[o];
    }
  };
  _creator.prototype.onClose = function () {};
  _creator.prototype._showOpenAnim = function () {
    var e = this;
    var t = this.node;
    var o = t.getChildByName("root") || t;
    if (this.showType == c.Sclae) {
      var n = o.scale;
      o.scale = .1;
      cc.tween(o).to(this._actTime, {
        scale: n
      }, {
        easing: ""
      }).call(function () {
        e._onOpenAnimOver();
      }).start();
    } else if (this.showType == c.Opacity) {
      o.opacity = 0;
      cc.tween(o).to(this._actTime, {
        opacity: 255
      }).call(function () {
        e._onOpenAnimOver();
      }).start();
    } else {
      this._onOpenAnimOver();
    }
  };
  _creator.prototype._onOpenAnimOver = function () {
    this.isFull && this._hideOtherViews();
  };
  _creator.prototype._clickListener = function () {};
  _creator.prototype._addEventListener = function () {};
  _creator.prototype._hideOtherViews = function () {
    var e = UIManager.default.getAllViews();
    var t = e.indexOf(this);
    for (var o = 0; o < e.length; o++) {
      var n = e[o];
      var i = n.node;
      var a = i.zIndex;
      if (n != this && i.active && t > a) {
        e[o].node.active = false;
        this._hideViews.push(e[o]);
      }
    }
  };
  _creator.prototype.showHideViews = function () {
    for (var e = 0; e < this._hideViews.length; e++) {
      var t = this._hideViews[e];
      t && t.node && (t.node.active = true);
    }
  };
  _creator.prototype._addClickListener = function () {
    var e;
    null === (e = this.auto_ui) || undefined === e || e.addClickListener(this._clickListener, this);
    var t = this._bundleName + "_" + this._uiName + "_block";
    var o = this.node.getChildByName(t);
    if (o) {
      var n = o.addComponent(cc.Button);
      UITools.default.addClickEvent(n, this._clickBlock, this);
    }
  };
  _creator.prototype._addEvent = function (e, t, o) {
    null != o || (o = this);
    var n = this._eventMap.get(e);
    if (n && o == n.target && t == n.callBack) {
      LogManager.LogMgr.error("重复注册事件:" + e);
    } else {
      EventManager.EventMgr.addEventListener(e, t, o);
      this._eventMap.set(e, {
        callBack: t,
        target: o
      });
    }
  };
  _creator.prototype.rmEvents = function () {
    this._eventMap.forEach(function (e, t) {
      var o = e.callBack;
      var n = e.target;
      EventManager.EventMgr.rmEventListener(t, o, n);
    });
    this._eventMap.clear();
  };
  _creator.prototype._clickBlock = function () {};
  __decorate([_property({
    displayName: "是否常驻",
    visible: function () {
      return !this._scene;
    }
  })], _creator.prototype, "isCache", undefined);
  __decorate([_property({
    displayName: "是否全屏",
    // tooltip: false,
    visible: function () {
      return !this._scene;
    }
  })], _creator.prototype, "isFull", undefined);
  __decorate([_property({
    type: cc.Enum(c),
    displayName: "打开方式",
    visible: function () {
      return !this._scene;
    }
  })], _creator.prototype, "showType", undefined);
  return __decorate([_ccclass, _menu("view/UIView")], _creator);
}(ResKeeper.default);
exports.default = _def_UIView;